package booksys.login;

import booksys.common.Utils;
import org.apache.ibatis.session.SqlSession;

public class LoginService {
    private booksys.common.Utils Utils;

    public boolean checkLogin(LoginDto dto) {

        SqlSession sqlSession = Utils.openSession();

        try{
            LoginDao dao = sqlSession.getMapper(LoginDao.class);
            int count;
            if(dto.getU_identity().equals("manager")){
                count = dao.findManagerCountByIdAndPwd(dto);
            }else
                count = dao.findStudentCountByIdAndPwd(dto);

            sqlSession.commit();

            return count > 0;
        }catch(Exception e){
            sqlSession.rollback();
            throw new RuntimeException(e);
        }finally{
            sqlSession.close();
        }


    }
}
